package com.tmy.controller;


import com.tmy.Dto.Result;
import com.tmy.entity.Collect;
import com.tmy.service.CollectService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;


/**
 * 收藏管理接口
 */

@RestController
@RequestMapping("/collect")
public class CollectController {

    @Resource
    private CollectService collectService;

    /**
     * 添加收藏
     */
    @PostMapping("/addCollect")
     public Result addCollect(@RequestBody Collect collect){
         Result result =new Result();
         try {
             return collectService.addCollect(collect);
         }catch (Exception err){
             result.setCode(500);
             result.setMsg(err.getCause());
             return result;
         }
     }
    /**
     * 取消收藏
     */
    @PostMapping("/deleteCollect")
    public Result deleteCollect(@RequestBody Collect collect){
        return collectService.deleteCollect(collect);
    }

    /**
     * 查询收藏
     */
    @PostMapping("/queryCollect")
    public Result queryCollect(@RequestBody Collect collect){
        Result result =new Result();
        try {
            if (!String.valueOf(collect.getUserId()).isEmpty()){
                return collectService.queryCollect(collect);
            }else {
                result.setMsg("userId不能为空！");
                result.setData(400);
                return result;
            }
        }catch (Exception err){
            result.setCode(500);
            result.setMsg(err.getCause());
            return result;
        }
    }
}